//
//  StationDetailView.m
//  AirQuality
//
//  Created by Mac on 16/1/22.
//  Copyright © 2016年 Po. All rights reserved.
//

#import "StationDetailView.h"

@interface StationDetailView ()

@property (retain, nonatomic) UIView * mainPollutionSection;           //主要污染物
@property (retain, nonatomic) UIView * last24HourSection;              //最近24小时

@end

@implementation StationDetailView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initInterface];
    }
    return self;
}

- (void)initInterface
{
    [self addSubview:[self getDetailscollowView]];
    [_detailScrollView addSubview:[self getMainPollutionSection]];
    [_detailScrollView addSubview:[self getLast24HourSection]];
}

- (UIScrollView *)getDetailscollowView
{
    if (!_detailScrollView) {
        _detailScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, self.frame.size.height)];
        _detailScrollView.showsVerticalScrollIndicator = NO;
        _detailScrollView.contentSize = CGSizeMake(ScreenWidth, 550);
        _detailScrollView.contentInset = UIEdgeInsetsMake(0, 0, 60, 0);
    }
    return _detailScrollView;
}

#pragma mark - mainPollution
- (UIView *)getMainPollutionSection
{
    if (!_mainPollutionSection) {
        _mainPollutionSection = [[UIView alloc] initWithFrame:CGRectMake(0, 180, ScreenWidth, 40)];
        [_mainPollutionSection addSubview:[self getSectionImage:@"OutMainPollution"]];
        
        [_mainPollutionSection addSubview:[self getMainSectionLabel:CGRectMake(25, 10, ScreenWidth, 20) title:@"污染物单位(CO:mg/m³   其他:µg/m³)"]];
        UILabel *unitLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, ScreenHeight, 20)];
        unitLable.font = [UIFont systemFontOfSize:12];
        unitLable.numberOfLines = 0;
        [_mainPollutionSection addSubview:unitLable];
    }
    return _mainPollutionSection;
}

#pragma mark - last24HourView
- (UIView *)getLast24HourSection
{
    if (!_last24HourSection) {
        _last24HourSection = [[UIView alloc] initWithFrame:CGRectMake(0, 335, ScreenWidth, 40)];
        [_last24HourSection addSubview:[self getSectionImage:@"OutLine"]];
        [_last24HourSection addSubview:[self getMainSectionLabel:CGRectMake(30, 10, ScreenWidth - 105, 20) title:@"历史数据"]];
//        [_last24HourSection.layer addSublayer:[self getSectionLineView]];
    }
    return _last24HourSection;
}

#pragma mark - public
- (UIImageView *)getSectionImage:(NSString *)imageName
{
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, 20, 20)];
    [imageView setImage:[UIImage imageNamed:imageName]];
    return imageView;
}

- (UILabel *)getMainSectionLabel:(CGRect)frame title:(NSString *)title
{
    UILabel * label = [[UILabel alloc] initWithFrame:frame];
    [label setTextColor:GetRGBColor(85, 85, 85, 1)];
    NSString * titleString = [[NSString stringWithFormat:@" "] stringByAppendingString:title];
    if (titleString.length >= 27) {
        NSUInteger length = titleString.length;
        NSUInteger index = [titleString rangeOfString:@"("].location;
        NSMutableAttributedString * attr = [[NSMutableAttributedString alloc] initWithString:titleString];
        [attr addAttribute:NSFontAttributeName
                     value:[UIFont systemFontOfSize:12.0]
                     range:NSMakeRange(index,length-index)];
        [label setAttributedText:attr];
        return label;
    }
    label.font = [UIFont systemFontOfSize:16];
    [label setText:titleString];
    return label;
}


@end
